﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Windows.Forms;
//using Microsoft.Office.Interop.Word;
using Word = Microsoft.Office.Interop.Word;

namespace ExtensionMethodsLambdaLINQ
{
    public class Student
    {
        public string FirstName { get; set; }
        public string LastName { get; set; }
    }
    public static class Extensions
    {
        public static int SumEnumerates(this IEnumerable<int> enumerable)
        {
            int sum = 0;
            foreach (var item in enumerable)
            {
                sum += item;
            }
            return sum;
        }
        public static double AvgEnumerates(this IEnumerable<int> enumerable)
        {
            int count = enumerable.Count();
            int sum = 0;
            foreach (var item in enumerable)
            {
                sum += item;
            }
            return (double)sum / count;
        }
        public static string CapitalizeFirst(this String str)
        {
            if (String.IsNullOrEmpty(str))
                return str;
            System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("zh-CHT");

            TextInfo info = CultureInfo.CurrentCulture.TextInfo;
            return info.ToTitleCase(str);
            //string result = char.ToUpper(str[0]).ToString();
            //result += str.Substring(1);
            //return result.ToString();
        }
    }

    class ExtensionMethods
    {
        static void Main(string[] args)
        {
            List<int> list = new List<int> { 1, 2, 3, 4, 5, 6 };

            int a = list.SumEnumerates();
            Console.WriteLine(a);
            double b = list.AvgEnumerates();
            Console.WriteLine(b);

            var students = new[] { new { FirstName = "SIvam", Family = "Petrov" }, new { FirstName = "Filip", Family = "Slanchev" } };
            var result =
                from s in students
                where s.FirstName[0] < s.Family[0]
                select s;
            foreach (var item in result)
            {
                Console.WriteLine(item);
            }

            int[] numbers = new int[] {1,2,3,4,5,6,7,8,9,21,14,15,42};
            var divisableto3and7 =
                from num in numbers
                where num % 3 == 0 //&& num % 7 ==0
                select num;
            foreach (var item in divisableto3and7)
            {
                Console.WriteLine(item);
            }

            string pesho = "此网站的目的是为了使浏览者能以正体字及简体字浏览中文";
            Console.WriteLine(pesho.CapitalizeFirst());
            
            //MessageBox.Show(info.ToTitleCase(pesho));

            //Word.ApplicationClass app = new ApplicationClass();

            //object nullobj = System.Reflection.Missing.Value;

            //object file = @"C:\gouse\Ques.doc";

            //Document doc = app.Documents.Open(ref file, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj, ref nullobj);

            //doc.ActiveWindow.Selection.WholeStory();

            //doc.ActiveWindow.Selection.Copy();

            //IDataObject data = Clipboard.GetDataObject();

            //string text = data.GetData(DataFormats.Text).ToString();

            //Console.WriteLine(text);

            //doc.Close(ref nullobj, ref nullobj, ref nullobj);

            //app.Quit(ref nullobj, ref nullobj, ref nullobj);
            int x = 6;
            if (x == 5 )
                Console.WriteLine(5);
            else
                Console.WriteLine(4);
        }
    }
}

